import java.util.*;
public class Main1 {
    static  class GiftBox implements  Comparable<GiftBox>{
        int length,width,height;
        public GiftBox(int length,int width,int height){
            this.length=length;
            this.width=width;
            this.height=height;
        }
        @Override
        public int compareTo(GiftBox o) {
            return o.length*o.width-this.length*this.width;
        }
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int maxH=0;
        GiftBox[] boxes=new GiftBox[N];
        for(int i=0;i<N;i++){
            int l=scanner.nextInt();
            int w=scanner.nextInt();
            int h=scanner.nextInt();
            boxes[i]=new GiftBox(l,w,h);
        }
        Arrays.sort(boxes);
        int[] dp=new int[boxes.length];
        for(int i=0;i<boxes.length;i++){
            dp[i]=boxes[i].height;
        }
        for(int i=0;i<boxes.length;i++){
            for(int j=0;j<i;j++){
                if(boxes[i].length<boxes[j].length && boxes[i].width<boxes[j].width &&  boxes[i].height<boxes[j].height){
                    dp[i]=Math.max(dp[j]+boxes[i].height,dp[i]);
                }
            }
            maxH=Math.max(maxH,dp[i]);
        }
        System.out.println(maxH);
    }

}
